package cn.zhf.shop.service.impl;

import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.lesson.Lesson;
import cn.zhf.shop.entity.organization.Organization;
import cn.zhf.shop.mapper.OrganizationMapper;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.zhf.shop.entity.lesson.LessonType;
import cn.zhf.shop.mapper.LessonTypeMapper;
import cn.zhf.shop.service.LessonTypeService;

import java.util.List;

@Component
public class LessonTypeServiceImpl implements LessonTypeService {

    @Resource
    private LessonTypeMapper lessonTypeMapper;
    @Resource
    private OrganizationMapper organizationMapper;

    @Override
    public Message deleteByPrimaryKey(Integer id) {

        List<Organization> organizationList = organizationMapper.selectByOrgType2(id);
        if (organizationList.size()>0)
        {
            return Message.fail("该条数据不能删除");
        }
        return Message.success(null).add(lessonTypeMapper.deleteByPrimaryKey(id));
    }

    @Override
    public Message insert(LessonType record) {
        return lessonTypeMapper.insert(record) > 0 ? Message.success(null) : Message.fail(null);
    }


    @Override
    public Message<LessonType> selectByPrimaryKey(Integer id) {
        LessonType refund = lessonTypeMapper.selectByPrimaryKey(id);
        return refund == null ? Message.fail("无记录") : Message.success(null).add(refund);
    }


    @Override
    public Message updateByPrimaryKey(LessonType record) {
        return lessonTypeMapper.updateByPrimaryKey(record) > 0 ? Message.success("更新成功" + record.getId()) : Message.fail("更新失败");
    }

    @Override
    public Message<List<LessonType>> getAll() {
        List<LessonType> refund = lessonTypeMapper.selectAll();
        return refund == null ? Message.fail("无记录") : Message.success(null).add(refund);
    }


    @Override
    public Message<List<LessonType>> H5getAll() {
        List<LessonType> refund = lessonTypeMapper.selectByTypeState(1);
        return refund == null ? Message.fail("无记录") : Message.success(null).add(refund);
    }

    @Override
    public String selectTypeNameById(Integer id) {
        if (lessonTypeMapper.selectTypeNameById(id)==null){
            return "暂无分类";
        }
        return lessonTypeMapper.selectTypeNameById(id);
    }

    @Override
    public int insertSelective(LessonType record) {
        return lessonTypeMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(LessonType record) {
        return lessonTypeMapper.updateByPrimaryKeySelective(record);
    }
}

